<?php
class PeriodsController extends AppController {
	public $name = 'Periods';
	public $uses = array('Period','Hero');
	public $components = array('Webservice.Webservice','RequestHandler');
	public $viewClass = 'Webservice.Webservice';
	
	function getAllPeriods(){
		//$this->RequestHandler->setContent('json', 'application/json');
		$periods = $this->Period->getListPeriods();
		if(isset($periods)){
			$dataOutput->massage = "successfully";
			$dataOutput->success = true;
			$dataOutput->response = $periods;
		}else{
			$dataOutput->massage = 'no database';
			$dataOutput->success = false;
		}
		$this->set(compact('dataOutput'));
	}
	function getPeriodById($id = null){
		//$this->RequestHandler->setContent('json', 'application/json');
		if(isset($id)){
			$period = $this->Period->getPeriodById($id);
			if(isset($period)){
				$dataOutput->massage = "successfully";
				$dataOutput->success = true;
				$dataOutput->response = $period;
				$dataOutput->responseHeroes = $this->Hero->getHeroesByPeriodId($id);
			}else{
				$dataOutput->massage = 'no database';
				$dataOutput->success = false;
			}
		}else{
			$dataOutput->massage = 'please! input period id';
			$dataOutput->success = false;
		}
		$this->set(compact('dataOutput'));
	}
	
	function getPeriodsByHeroId($id = null){
		//$this->RequestHandler->setContent('json', 'application/json');
		if(isset($id)){
			$periods = $this->Period->getPeriodsByHeroId($id);
			if(isset($periods)){
				$dataOutput->massage = "successfully";
				$dataOutput->success = true;
				$dataOutput->response = $periods;
			}else{
				$dataOutput->massage = 'no database';
				$dataOutput->success = false;
			}
		}else{
			$dataOutput->massage = 'please! input period id';
			$dataOutput->success = false;
		}
		$this->set(compact('dataOutput'));
	}
	
	function getPeriodsByName($name = null){
		if(isset($name)){
			$periods = $this->Period->getPeriodsByName($name);
			if(!empty($periods)){
				$dataOutput->massage = "successfully";
				$dataOutput->success = true;
				$dataOutput->response = $periods;
			}else{
				$dataOutput->massage = 'no database';
				$dataOutput->success = false;
			}
		}else{
			$periods = $this->Hero->getListPeriods();
			if(isset($periods)){
				$dataOutput->massage = "successfully";
				$dataOutput->success = true;
				$dataOutput->response = $periods;
			}else{
				$dataOutput->massage = 'no database';
				$dataOutput->success = false;
			}
		}
		$this->set(compact('dataOutput'));
	}
	
	
}
?>